//
//  TWOstuDetailsVC.m
//  YaoHeAPP
//
//  Created by xyh on 16/4/14.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "TWOstuDetailsVC.h"
#import "Masonry.h"

#import "Controller.h"
#import "MyOrderData.h"
#import "MyorderDataList.h"
#import "TongYong.h"

#import "orderCell.h"

#import "DetaileButandLabelCell.h"

#import "orderHeaderView.h"

#import "moneybuyCV.h"


#import "NOstuDetailVC.h"


#import "GeneraldetailsVC.h"

#import "huopinVC.h"

#define screenWidth self.view.frame.size.width
#define screenHeight self.view.frame.size.height
#define bgVCcolor [UIColor colorWithRed:235.f/255.f green:235.f/255.f blue:244.f/255.f alpha:1]
@interface TWOstuDetailsVC ()<UITableViewDelegate,UITableViewDataSource,moneybuyCVdelgaet>
{
    
    UIView *topview;//顶部两个列表
    NSMutableArray *arrayList;
    
    NSString *dingdanhaost;
    NSString *statusst;
    NSString *compayst;
    NSString *numst;
    
    float shifuMoney;//实付金额
    UILabel *shifuTextBootm;
    UILabel *shifuText;
    
    NSMutableArray *MoneytextArray;//费用
    
    NSMutableArray *timearray;//下单时间  下单账号  下单人
    
    //倒计时
    NSMutableArray *totalLastTime;
    
    NSTimer *timer;
    
    
}
@property(nonatomic,strong) UITableView *tableview;

@end

@implementation TWOstuDetailsVC


//视图将要消失的时候将定时器关闭
- (void)viewDidDisappear:(BOOL)animated {
    if (timer.isValid) {
        [timer invalidate];
    }
    timer=nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"TWOstuDetailsVC"];
    
    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"TWOstuDetailsVC"];
    
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBar.hidden=YES;
    
    self.view.backgroundColor=bgVCcolor;
    //加一个导航条
    UIView*navcBar=[[UIView alloc]init];
    navcBar.backgroundColor=[UIColor colorWithRed:90.f/255.f green:191.f/255.f blue:219.f/255.f alpha:1];
    [self.view addSubview:navcBar];
    [self.view bringSubviewToFront:navcBar];
    [navcBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);   make.left.offset(0);
        make.height.offset(140);  make.right.offset(0);
    }];
    //导航条标题
    UILabel*titleLabel=[[UILabel alloc]init];
    titleLabel.text=@"待支付订单";
    titleLabel.font=Font(17);
    titleLabel.textAlignment=NSTextAlignmentCenter;
    titleLabel.textColor=[UIColor whiteColor];
    [navcBar addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(25);
        make.left.offset(self.view.frame.size.width/2-70);
        make.width.offset(140);
        make.height.offset(30);
    }];
    
    //返回按钮
    UIButton*leftButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [leftButton setBackgroundImage:[UIImage imageNamed:@"return"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(backLogin) forControlEvents:UIControlEventTouchUpInside];
    [navcBar addSubview:leftButton];
    [leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(6);
        make.width.offset(24);
        make.height.offset(22);
        make.top.offset(31);
    }];
    
    //顶部数组
    
    //中间线长度
    NSInteger online=(screenWidth-(30*3)-(40*2))/2;
    NSInteger jianju=(screenWidth-(60*3)-(25*2))/2;
    NSInteger yuanWandH=30;
    NSArray *topArray=@[@"确认订单",@"支付订单",@"已结算"];
    for (int i=0; i<topArray.count; i++) {
        UILabel *yuan=[[UILabel alloc]init];
        yuan.frame=CGRectMake(40+(30+online)*i, 140-15-30-10-20, yuanWandH, yuanWandH);
        yuan.layer.masksToBounds=YES;
        yuan.text=[NSString stringWithFormat:@"%d",i+1];
        yuan.textAlignment=NSTextAlignmentCenter;
        yuan.textColor=[UIColor whiteColor];
        yuan.tag=10+i;
        yuan.layer.cornerRadius=15;
        [navcBar addSubview:yuan];
        
        UILabel *toplable=[[UILabel alloc]init];
        toplable.frame=CGRectMake(25+(60+jianju)*i, 140-15-30-10-20+30+5, 60, 30);
        toplable.text=topArray[i];
        toplable.textAlignment=NSTextAlignmentCenter;
        toplable.font=[UIFont systemFontOfSize:14];
        toplable.textColor=[UIColor whiteColor];
        toplable.tag=100+i;
        
        if (i==0||i==1) {
            
            yuan.backgroundColor=[UIColor colorWithRed:146.f/255.f green:198.f/255.f blue:35.f/255.f alpha:1];
            yuan.alpha=1;
            
            toplable.alpha=1;
        }else{
            yuan.backgroundColor=[UIColor colorWithRed:91.f/255.f green:140.f/255.f blue:152.f/255.f alpha:0.5];
            yuan.alpha=0.5;
            
            toplable.alpha=0.5;
        }
        
        [navcBar addSubview:toplable];
        
        
    }
    
    for (int j=0; j<topArray.count-1; j++) {
        
        UIImageView *onlineimg=[[UIImageView alloc]init];
        
        if (j==0) {
            onlineimg.backgroundColor=[UIColor colorWithRed:146.f/255.f green:198.f/255.f blue:35.f/255.f alpha:1];
        }else{
            onlineimg.backgroundColor=[UIColor colorWithRed:91.f/255.f green:140.f/255.f blue:152.f/255.f alpha:0.5];
        }
        
        onlineimg.frame=CGRectMake(40+yuanWandH*(j+1)+online*j, 140-15-30-10-20+15, online, 1);
        [navcBar addSubview:onlineimg];
        
    }
    
    //订单号   公司名称
    topview =[[UIView alloc]initWithFrame:CGRectMake(0, 140, screenWidth, 84)];
    topview.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:topview];
    
    //订单名称和订单号
    UILabel  *companyorderlabel=[[UILabel alloc]initWithFrame:CGRectMake(10, 11, 165, 20)];
    companyorderlabel.textAlignment=NSTextAlignmentLeft;
    companyorderlabel.font=[UIFont systemFontOfSize:12];
    companyorderlabel.tag=9000;
    [topview addSubview:companyorderlabel];
    
    //状态
    UILabel  *statusla=[[UILabel alloc]initWithFrame:CGRectMake(screenWidth-100-10, 11, 100, 20)];
    statusla.textAlignment=NSTextAlignmentRight;
    statusla.font=[UIFont systemFontOfSize:12];
    statusla.textColor=[UIColor colorWithRed:251.f/255.f green:87.f/255.f blue:60.f/255.f alpha:1];
    statusla.tag=9001;
    [topview addSubview:statusla];
    
    UIImageView *line=[[UIImageView alloc]initWithFrame:CGRectMake(0, 42, self.view.frame.size.width, 1)];
    line.backgroundColor=[UIColor colorWithRed:230/255.0 green:232/255.0 blue:241/255.0  alpha:1];
    [topview addSubview:line];
    
    //公司名称
    
    UILabel  *comlabel=[[UILabel alloc]initWithFrame:CGRectMake(10, 53, 165, 20)];
    comlabel.textAlignment=NSTextAlignmentLeft;
    comlabel.font=[UIFont systemFontOfSize:12];
    comlabel.textColor=[UIColor colorWithRed:57.f/255.f green:93.f/255.f blue:124.f/255.f alpha:1];
    comlabel.tag=9002;
    [topview addSubview:comlabel];
    
    UILabel  *numla=[[UILabel alloc]initWithFrame:CGRectMake(screenWidth-100-10-20, 53, 100, 20)];
    numla.textAlignment=NSTextAlignmentRight;
    numla.font=[UIFont systemFontOfSize:12];
    numla.textColor=[UIColor colorWithRed:135.f/255.f green:135.f/255.f blue:135.f/255.f alpha:1];
    numla.tag=9003;
    [topview addSubview:numla];
    
    UIImageView *jiantouImageV=[[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-10-10, 55.5, 10, 15)];
    jiantouImageV.image=[UIImage imageNamed:@"ic_arraw"];
    [topview addSubview:jiantouImageV];
    //大的按钮点击进订单界面
    UIButton *orderBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    orderBtn.frame=CGRectMake(0, 43, self.view.frame.size.width, 40);
    orderBtn.backgroundColor=[UIColor clearColor];
    [orderBtn addTarget:self action:@selector(orderBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [topview addSubview:orderBtn];

    
    //下面打电话试图
    //下部按钮
    UIView *bootmView=[[UIView alloc]init];
    bootmView.backgroundColor=[UIColor whiteColor];
    bootmView.frame=CGRectMake(0,screenHeight-50, screenWidth, 50);
    [self.view addSubview:bootmView];

    UIImageView *fenimg=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, 1)];
    fenimg.backgroundColor=[UIColor colorWithRed:230/255.0 green:232/255.0 blue:241/255.0  alpha:1];
    [bootmView addSubview:fenimg];
    
    
    UIButton *leftbutton=[[UIButton alloc]initWithFrame:CGRectMake(screenWidth-10-76-10-76, 13, 76, 24)];
    [bootmView addSubview:leftbutton];
    leftbutton.layer.borderWidth=1;
    leftbutton.layer.borderColor=[UIColor colorWithRed:193/255.0 green:193/255.0 blue:193/255.0  alpha:1].CGColor;
    leftbutton.backgroundColor=[UIColor whiteColor];
    leftbutton.tag=10000;
    [leftbutton setTitle:@"取消订单" forState:UIControlStateNormal];
    leftbutton.titleLabel.font=[UIFont systemFontOfSize:14];
    [leftbutton setTitleColor:[UIColor colorWithRed:80/255.0 green:84/255.0 blue:85/255.0  alpha:1] forState:UIControlStateNormal];
    [leftbutton addTarget:self action:@selector(leftbuttonAction) forControlEvents:UIControlEventTouchUpInside];


    UIButton *rightbutton=[[UIButton alloc]initWithFrame:CGRectMake(screenWidth-10-76, 13, 76, 24)];
    [bootmView addSubview:rightbutton];
    rightbutton.backgroundColor=[UIColor colorWithRed:251/255.0 green:87/255.0 blue:60/255.0  alpha:1];
    [rightbutton setTitle:@"去支付" forState:UIControlStateNormal];
    rightbutton.tag=20000;
    rightbutton.titleLabel.font=[UIFont systemFontOfSize:14];
    [rightbutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [rightbutton addTarget:self action:@selector(rightbuttonAction) forControlEvents:UIControlEventTouchUpInside];

    
    
    UILabel *rightlabel=[[UILabel alloc]initWithFrame:CGRectMake(10,0, screenWidth-80-25, 20)];
    NSString *st;
    st=[NSString stringWithFormat:@"付款倒计时"];
    rightlabel.textAlignment=NSTextAlignmentLeft;
    rightlabel.font=[UIFont systemFontOfSize:12];
    rightlabel.text=st;
    rightlabel.textColor=[UIColor colorWithRed:251/255.0 green:87/255.0 blue:60/255.0  alpha:1];
    [bootmView addSubview:rightlabel];


    UIImageView *timeimg=[[UIImageView alloc]initWithFrame:CGRectMake(10, 22.5, 15, 15)];
    timeimg.image=[UIImage imageNamed:@"daojishi"];
    [bootmView addSubview:timeimg];
    
    
    //倒计时时间
    shifuTextBootm=[[UILabel alloc]initWithFrame:CGRectMake(30, 20, screenWidth-10-76-10-76-40, 20)];
    shifuTextBootm.font=[UIFont systemFontOfSize:12];
    shifuTextBootm.textAlignment=NSTextAlignmentLeft;
    shifuTextBootm.textColor=[UIColor colorWithRed:251/255.0 green:87/255.0 blue:60/255.0  alpha:1];
    [bootmView addSubview:shifuTextBootm];
    
    

    //定义数组
    arrayList=[[NSMutableArray alloc]init];
    
    MoneytextArray=[[NSMutableArray alloc]init];
    
    timearray=[[NSMutableArray   alloc]init];
    
    totalLastTime=[[NSMutableArray alloc]init];
    
    //请求数据
    [self getdetailData];
    
    
    
}

//进入货品清单
-(void)orderBtnAction
{
    //取出对应段落的数据
    MyOrderData *order3=[[MyOrderData alloc]initWith:arrayList[0]];
    
    NSMutableArray *OrderArray=[[NSMutableArray alloc]init];
    OrderArray= order3.pro_data;
    //    货品清单
    huopinVC *hpVc=[[huopinVC alloc]init];
    hpVc.OrderArray=OrderArray;
    hpVc.isXianhuo=@"订单详情";
    hpVc.zongmoney=order3.total_sales;
    [self.navigationController pushViewController:hpVc animated:YES];
}



//取消订单
-(void)leftbuttonAction{
    
   MyOrderData *order7=[[MyOrderData alloc]initWith:arrayList[0]];

   NSMutableDictionary *dic=[[NSMutableDictionary alloc]init];
   [dic setValue:order7.intent_order_id forKey:@"intent_order_id"];
   [Controller requestWithURL:CANCELORDER jsondic:dic finishBlock:^(ClassData* data) {
    if ([data.number isEqualToNumber:[NSNumber numberWithInteger:0]])
    {
        //让定时器无效
        [timer invalidate];
        
        NOstuDetailVC *generalVC=[[NOstuDetailVC alloc]init];
        generalVC.isdaizhifu=self.isdaizhifu;
        generalVC.intent_order_id=order7.intent_order_id;
        [self.navigationController pushViewController:generalVC animated:YES];
        
        //通知刷新传过来的列表数据
        
        if ([self.isdaizhifu isEqualToString:@"全部订单列表"]) {
            
            [[NSNotificationCenter defaultCenter] postNotificationName:@"allorderlist" object:nil];
        
        }else if ([self.isdaizhifu isEqualToString:@"待支付列表"]) {
            
            [[NSNotificationCenter defaultCenter] postNotificationName:@"daizhifuorderlist" object:nil];
            
        }
        
        
        
        
        
    }
    else
    {
        
    }
}];

}

//去支付
-(void)rightbuttonAction
{
        [MobClick event:@"daizhifuxiangqing_zhifu"];
    
        MyOrderData *order7=[[MyOrderData alloc]initWith:arrayList[0]];
        moneybuyCV *moneyvc=[[moneybuyCV alloc]init];
        moneyvc.pay_type=@"10";
        moneyvc.intent_order_id=order7.intent_order_id;
        moneyvc.delegate=self;
        //获取当前时间值
        NSTimeInterval timest = [[NSDate date] timeIntervalSince1970];
        NSInteger timeintage=timest;
        NSString *sttime=order7.expired_time;
        NSInteger extime=sttime.integerValue/1000;
        NSInteger timevely=timeintage+extime;
        moneyvc.odertime=[NSString stringWithFormat:@"%ld",(long)timevely];

        [self.navigationController pushViewController:moneyvc animated:YES];
        

}
//支付成功刷新界面
-(void)uporderlist
{
    //让定时器无效
    [timer invalidate];

    MyOrderData *order7=[[MyOrderData alloc]initWith:arrayList[0]];
    GeneraldetailsVC *generalVC=[[GeneraldetailsVC alloc]init];
    generalVC.intent_order_id=order7.intent_order_id;
    generalVC.isdaizhifu=self.isdaizhifu;
    [self.navigationController pushViewController:generalVC animated:YES];
    
    
}


-(void)getdetailData
{
    //获取
    NSMutableDictionary *di=[[NSMutableDictionary alloc]init];
    [di setValue:@"" forKey:@"member_id"];
    [di setValue:self.intent_order_id forKey:@"intent_order_id"];
    //要判断什么类型的然后穿的参数不同
    [Controller requestWithURL:NEEDPAYORDERDETAIL jsondic:di finishBlock:^(ClassData* data) {
        
        if ([data.number isEqualToNumber:[NSNumber numberWithInteger:0]])
        {
            [arrayList addObjectsFromArray:data.data[@"data"]];
            
            MyOrderData *order=[[MyOrderData alloc]initWith:arrayList[0]];
        
            
            NSString *miaost=order.expired_time;
            NSInteger miao=miaost.integerValue/1000;
            NSString *stm=[NSString stringWithFormat:@"%ld",(long)miao];
            NSDictionary *dic = @{@"indexPath":[NSString stringWithFormat:@"%i",0],@"lastTime":stm};
            [totalLastTime addObject:dic];
            [self startTimer];
            
            
            [timearray addObject:[NSString stringWithFormat:@"下单时间:%@",order.create_time]];
            [timearray addObject:[NSString stringWithFormat:@"下单账号:%@",order.operator_mobile]];
            [timearray addObject:[NSString stringWithFormat:@"下 单 人:%@",order.operator_name]];
            
            float zong=order.total_sales.floatValue;
            float chu=order.outbound_amount.floatValue;
            float yuouhui=order.discount_amount.floatValue;
            float duanbofei=order.short_amount.floatValue;
            
            double shi=order.total_payable.doubleValue;
            
            NSString *zongst=[NSString stringWithFormat:@"￥%.2f",zong];
            NSString *chust=[NSString stringWithFormat:@"+￥%.2f",chu];
            NSString *duanbofeist=[NSString stringWithFormat:@"+￥%.2f",duanbofei];
            NSString *yuohuist=[NSString stringWithFormat:@"-￥%.2f",yuouhui];
            
            [MoneytextArray addObject:zongst];
            [MoneytextArray addObject:chust];
            [MoneytextArray addObject:duanbofeist];
            [MoneytextArray addObject:yuohuist];

            
            shifuMoney=shi;
            
            
            //创建表格
            _tableview=[[UITableView alloc]initWithFrame:CGRectMake(0,230, self.view.frame.size.width, self.view.frame.size.height-230-50) style:UITableViewStylePlain];
            _tableview.backgroundColor= [UIColor colorWithRed:230/255.0 green:232/255.0 blue:241/255.0  alpha:1];
            _tableview.delegate=self;
            _tableview.dataSource=self;
            _tableview.separatorStyle=NO;
            
            [self.view addSubview:_tableview];

            
            
//            [_tableview reloadData];
            
            dingdanhaost=[NSString stringWithFormat:@"订单号:%@",arrayList[0][@"intent_order_code"]];
            
            NSString *st=arrayList[0][@"status"];
            NSInteger status=st.integerValue;
            if (status==10) {
                statusst=@"待支付";
            }else if(status==15){
                statusst=@"已付定金";
            }else if(status==20){
                statusst=@"已结算";
            }else if(status==-1){
                statusst=@"已失效";
            }else if(status==40){
                statusst=@"已退款";
            }

            compayst=arrayList[0][@"invoice_company"];
//            numst=[NSString stringWithFormat:@"共%@件",arrayList[0][@"total_quantity"]];
            NSMutableArray *OrderArray=[[NSMutableArray alloc]init];
            OrderArray= order.pro_data;
            numst=[NSString stringWithFormat:@"共%lu件",(unsigned long)OrderArray.count];
            
            [self loadmeagesView];
            
        }else
        {
            ALERTSHOW(data.message);
            
            
        }
    }];
    
    
    
    
}

#pragma mark ------------开启定时器方法--------
//开启定时器方法：
- (void)startTimer
{
    if (timer.isValid) {
        [timer invalidate];
    }
    timer=nil;
    
    timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(refreshLessTime) userInfo:@"" repeats:YES];
    
    //    如果不添加下面这条语句，在UITableView拖动的时候，会阻塞定时器的调用
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:UITrackingRunLoopMode];
    
}

//主要的定时器中的方法，在该方法中，遍历totalLastTime，取出其中保存的lasttime和indexpath，time用来显示，在显示完后自减，indexpath代表对应显示的位置，在一次循环后，将新的time和没有改变的indexpath从新替换totalLastTime 中对应位置的元素，以此保证每一秒执行时，显示time都是最新的。
- (void)refreshLessTime
{
    NSInteger time;
    for (int i = 0; i < totalLastTime.count; i++) {
        
        time = [[[totalLastTime objectAtIndex:i] objectForKey:@"lastTime"] integerValue];
        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:[[[totalLastTime objectAtIndex:i] objectForKey:@"indexPath"] integerValue]];
        
        if (time<=0) {
           //提示过期
            MyOrderData *order=[[MyOrderData alloc]initWith:arrayList[0]];

            
            NSString *me=[NSString stringWithFormat:@"您的订单：%@ 已过期",order.intent_order_code];
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                            message:me
                                                           delegate:self
                                                  cancelButtonTitle:@"取消"
                                                  otherButtonTitles:nil];
            alert.tag = 0;
            [alert show];
            //移除该条倒计时
            [totalLastTime removeObjectAtIndex:i];
            
        }else{
            
            
            NSString *ss=[NSString stringWithFormat:@"%@",[self lessSecondToDay:--time]];
            shifuTextBootm.text=ss;
            NSDictionary *dic = @{@"indexPath": [NSString stringWithFormat:@"%li",(long)indexPath.section],@"lastTime": [NSString stringWithFormat:@"%lu",(unsigned long)time]};
            [totalLastTime replaceObjectAtIndex:i withObject:dic];
            
        }
        
        
    }
}

- (NSString *)lessSecondToDay:(NSInteger)seconds
{
    //    NSUInteger day  = (NSUInteger)seconds/(24*3600);
    NSInteger hour = (NSInteger)(seconds%(24*3600))/3600;
    NSInteger min  = (NSInteger)(seconds%(3600))/60;
    NSInteger second = (NSInteger)(seconds%60);
    
    NSString *time = [NSString stringWithFormat:@"%ld时%ld分%ld秒",(long)hour,(long)min,(long)second];
    return time;
    
}











-(void)loadmeagesView
{
    UILabel *dingdan=[topview viewWithTag:9000];
    dingdan.text=dingdanhaost;
    
    UILabel *statusla=[topview viewWithTag:9001];
    statusla.text=statusst;
    
    UILabel *compay=[topview viewWithTag:9002];
    compay.text=compayst;
    
    UILabel *numla=[topview viewWithTag:9003];
    numla.text=numst;
    
}


#pragma  mark--------------表格代理方法-----------------
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    MyOrderData *order=[[MyOrderData alloc]initWith:arrayList[section]];
    

    return order.pro_data.count+2;
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    MyOrderData *order=[[MyOrderData alloc]initWith:arrayList[indexPath.section]];
    
    if (indexPath.row==order.pro_data.count+1) {
        
        return 170;
        
    }
    
    if (indexPath.row==order.pro_data.count) {
        
        return 90;
        
    }
    
    
    return 70;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //取出对应段落的数据
    MyOrderData *order3=[[MyOrderData alloc]initWith:arrayList[indexPath.section]];
    

    for (int i=0; i<order3.pro_data.count; i++) {
        
    if (indexPath.row==i) {
        
        MyorderDataList *orderListData=[[MyorderDataList alloc]initWith:order3.pro_data[indexPath.row]];
        
        //指定cellIdentifier为自定义的cell
        static NSString *CellIdentifier = @"orderCell";
        //自定义cell类
        orderCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        //无色
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        if (cell == nil) {
            //通过xib的名称加载自定义的cell
            cell = [[[NSBundle mainBundle] loadNibNamed:@"orderCell" owner:self options:nil] lastObject];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        //    4.1.1订单列表：展示货品参数
    //    展示购买的货品：
    //    型材 、管材 ： 品类（如扁钢等）、 材质、 规格、形状（如方管、圆管等，客户没有上传就不展示）、重量（总重）、数量、所在地、产地；
    //    卷、板、带：材质、表面、 规格(厚度*宽度*长度） 参厚 等级 重量（总重） 仓库、产地；
    
    
    //顶部字符串拼接
    NSString *toplable;
    if ([TongYong isBlankObjectAndStr:orderListData.suface_code]) {
        toplable=[NSString stringWithFormat:@"%@ %@",orderListData.category_name,orderListData.material_code];
    }else{
        toplable=[NSString stringWithFormat:@"%@ %@/%@",orderListData.category_name,orderListData.material_code,orderListData.suface_code];
        
    }
    
    NSString *guige=orderListData.spec_code;
    
    //参厚
    NSString *canhou;
    if ([TongYong isBlankObjectAndStr:orderListData.reference_thick ]) {
        canhou=@"";
    }else{
        canhou=[NSString stringWithFormat:@"(%@)",orderListData.reference_thick];
    }
    
    //边部
    NSString *bianbu;
    if ([TongYong isBlankObjectAndStr:orderListData.edge_name ]) {
        bianbu=@"";
    }else{
        
        bianbu=[NSString stringWithFormat:@"/%@",orderListData.edge_name];
        
    }
    
    //等级
    NSString *dengji;
    if ([TongYong isBlankObjectAndStr:orderListData.level_name ]) {
        
        dengji=@"";
        
    }else{
        
        dengji=[NSString stringWithFormat:@"/%@",orderListData.level_name];
        
    }
    
    
    //包装
    NSString *baozhuang;
    if ([TongYong isBlankObjectAndStr:orderListData.package_type ]) {
        
        baozhuang=@"";
        
    }else{
        //包装类型//(30,"裸包"),(10,"简包"),(20,"精包"),(0,"正常包装")
        NSInteger typ=orderListData.package_type.integerValue;
        if (typ==30) {
            baozhuang=[NSString stringWithFormat:@"/裸包"];
        }else if(typ==20){
            baozhuang=[NSString stringWithFormat:@"/精包"];
        }else if(typ==10){
            baozhuang=[NSString stringWithFormat:@"/简包"];
        }else{
            
            baozhuang=[NSString stringWithFormat:@"正常包装"];
        }
    }
    
    
    //形状
    NSString *xinzhuang;
    if ([TongYong isBlankObjectAndStr:orderListData.shape_name ]) {
        
        xinzhuang=@"";
        
    }else{
        
        xinzhuang=[NSString stringWithFormat:@"/%@",orderListData.shape_name];
        
    }
    
    //品名
    NSString *pingming;
    if ([TongYong isBlankObjectAndStr:orderListData.category_name ]) {
        
        pingming=@"";
        
    }else{
        
        pingming=[NSString stringWithFormat:@"/%@",orderListData.category_name];
        
    }
    
    
    
    NSString *bigTEXT;
    if ([orderListData.category_name isEqualToString:@"板"]||[orderListData.category_name isEqualToString:@"卷"]||[orderListData.category_name isEqualToString:@"板材"]||[orderListData.category_name isEqualToString:@"卷材"]) {
        //		板卷   规格(参厚)/边部/等级/包装
        
        bigTEXT=[NSString stringWithFormat:@"%@  %@%@%@/%ld/%.3f公斤",toplable,guige,canhou,dengji,(long)orderListData.quantity.integerValue,orderListData.weight.floatValue*orderListData.quantity.integerValue];
        
        
    }else{
        
        bigTEXT=[NSString stringWithFormat:@"%@  %@%@/%ld/%.3f公斤",toplable,guige,bianbu,(long)orderListData.quantity.integerValue,orderListData.weight.floatValue*orderListData.quantity.integerValue];
    }
        
    
    cell.bigLable.text=bigTEXT;
    
    
    //仓库  生产商
    NSString *ck;
    if ([TongYong isBlankObjectAndStr:orderListData.house_name ]) {
        
        ck=@"";
        
    }else{
        
        ck=[NSString stringWithFormat:@"%@",orderListData.house_name];
        
    }
    
    NSString *scs;
    if ([TongYong isBlankObjectAndStr:orderListData.manufacturer_name ]) {
        
        scs=@"";
        
    }else{
        
        scs=[NSString stringWithFormat:@"%@",orderListData.manufacturer_name];
        
    }
    
    cell.addandhous.text=[NSString stringWithFormat:@"%@    %@",ck,scs];
        
    
    return cell;
        
  }
    
        
}
    
    NSString *identifier = [NSString stringWithFormat:@"TimeLineCell%ld%ld",(long)indexPath.section,(long)indexPath.row];
    //自定义cell类有图片
    UITableViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:identifier];
   
    if (cell2 == nil) {
        
        cell2 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell2.selectionStyle=UITableViewCellSelectionStyleNone;
        cell2.backgroundColor=[UIColor whiteColor];
        
        if (indexPath.row==order3.pro_data.count) {
            
            
            UILabel *lab=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width+10, 2)];
            lab.text=@" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -";
            lab.textColor=[UIColor colorWithRed:204.f/255.f green:204.f/255.f blue:204.f/255.f alpha:1];
            //            lab.backgroundColor=[UIColor whiteColor];
            [cell2 addSubview:lab];

            
            for (int j=0; j<3; j++) {
                
                UILabel *youhui=[[UILabel alloc]initWithFrame:CGRectMake(10, 10+(20+5)*j, screenWidth-20, 20)];
                youhui.font=[UIFont systemFontOfSize:12];
                youhui.tag=800+j;
                youhui.text=timearray[j];
                youhui.textAlignment=NSTextAlignmentLeft;
                youhui.textColor=[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0  alpha:1];
                [cell2 addSubview:youhui];
                
            }
            
            
        }
      
        
        if (indexPath.row==order3.pro_data.count+1) {
        
                    cell2.backgroundColor=[UIColor colorWithRed:230/255.0 green:232/255.0 blue:241/255.0  alpha:1];
        
                    UIView *fatherView=[[UIView alloc]initWithFrame:CGRectMake(0, 10, screenWidth, 160)];
                    fatherView.backgroundColor=[UIColor whiteColor];
                    [cell2 addSubview:fatherView];
        
        
                    NSArray *array=@[@"货品总金额",@"出库费",@"短驳费",@"优惠金额"];
                    for (int i=0; i<array.count; i++) {
        
                        UILabel  *youhui=[[UILabel alloc]initWithFrame:CGRectMake(10, 10+(20+10)*i, 80, 20)];
                        youhui.text=array[i];
                        youhui.font=[UIFont systemFontOfSize:13];
                        youhui.textAlignment=NSTextAlignmentLeft;
                        youhui.textColor=[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0  alpha:1];
                        [fatherView addSubview:youhui];
        
        
                        UILabel  *youhuiText=[[UILabel alloc]initWithFrame:CGRectMake(100, 10+(20+10)*i, screenWidth-100-10, 20)];
                        youhuiText.text=MoneytextArray[i];
                        youhuiText.tag=1000+i;
                        youhuiText.font=[UIFont systemFontOfSize:13];
                        youhuiText.textAlignment=NSTextAlignmentRight;
                        youhuiText.textColor=[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0  alpha:1];
                        [fatherView addSubview:youhuiText];
        
        
                    }
        
                    //实付款
                    shifuText=[[UILabel alloc]initWithFrame:CGRectMake(100, 130, screenWidth-100-10, 20)];
                    //        shifuText.text=@"实付款：￥150150";
                    shifuText.font=[UIFont systemFontOfSize:13];
                    shifuText.textAlignment=NSTextAlignmentRight;
                    shifuText.textColor=[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0  alpha:1];
                    [fatherView addSubview:shifuText];
            
                    //指定位置变色
                     NSString *ss=[NSString stringWithFormat:@"实付款:￥%.2f",shifuMoney];
                     NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:ss];
                     NSRange redRange = NSMakeRange([[noteStr string] rangeOfString:@":"].location+1,noteStr.length-4 );
                     [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange];
                     [shifuText setAttributedText:noteStr] ;

            
                    
                }

        
        
        
    }
    
    
//      if (indexPath.row==order3.pro_data.count){
//        
//           for (int i=0; i<3; i++) {
//            
//            UILabel *time_label = (UILabel *)[cell2 viewWithTag:i+800];
//            
//            time_label.text=timearray[i];
//            
//            
//         }
//        
//        
//        
//      }
//    
//
//    
//    
//    
//        if (indexPath.row==order3.pro_data.count+1) {
//    
//            //指定位置变色
//            NSString *ss=[NSString stringWithFormat:@"实付款:￥%.2f",shifuMoney];
//            NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:ss];
//            NSRange redRange = NSMakeRange([[noteStr string] rangeOfString:@":"].location+1,noteStr.length-4 );
//            [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange];
//            [shifuText setAttributedText:noteStr] ;
//    
//    
//            for (int i=0; i<3; i++) {
//    
//                UILabel *find_label = (UILabel *)[cell2 viewWithTag:i+1000];
//    
//                find_label.text=MoneytextArray[i];
//                
//                
//            }
//            
//            
//            
//        }
//
    
    
    
    
    return cell2;
    
    
//    NSString *identifier = [NSString stringWithFormat:@"TimeLineCell%ld%ld",(long)indexPath.section,(long)indexPath.row];
//    //自定义cell类有图片
//    UITableViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:identifier];
//    if (cell2 == nil) {
//        
//        cell2 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
//        cell2.selectionStyle=UITableViewCellSelectionStyleNone;
//        cell2.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
//        cell2.backgroundColor=[UIColor whiteColor];
//
//    
//    if (indexPath.row==order3.pro_data.count) {
//        
//        for (int j=0; j<3; j++) {
//                
//                UILabel *youhui=[[UILabel alloc]initWithFrame:CGRectMake(10, 10+(20+5)*j, screenWidth-20, 20)];
//                youhui.font=[UIFont systemFontOfSize:12];
//                youhui.tag=800+j;
//                youhui.textAlignment=NSTextAlignmentLeft;
//                youhui.textColor=[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0  alpha:1];
//                [cell2 addSubview:youhui];
//                
//            }
//            
//        }
//
//       
//        if (indexPath.row==order3.pro_data.count+1) {
//            
//            
//            cell2.backgroundColor=[UIColor colorWithRed:230/255.0 green:232/255.0 blue:241/255.0  alpha:1];
//            
//            UIView *fatherView=[[UIView alloc]initWithFrame:CGRectMake(0, 10, screenWidth, 200)];
//            fatherView.backgroundColor=[UIColor whiteColor];
//            [cell2 addSubview:fatherView];
//            
//            
//            NSArray *array=@[@"货品总金额",@"出库费",@"优惠金额"];
//            for (int i=0; i<array.count; i++) {
//                
//                UILabel  *youhui=[[UILabel alloc]initWithFrame:CGRectMake(10, 10+(20+10+10)*i, 60, 20)];
//                youhui.text=array[i];
//                youhui.font=[UIFont systemFontOfSize:12];
//                youhui.textAlignment=NSTextAlignmentLeft;
//                youhui.textColor=[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0  alpha:1];
//                [fatherView addSubview:youhui];
//                
//                
//                 UILabel  *youhuiText=[[UILabel alloc]initWithFrame:CGRectMake(80, 10+(20+10+10)*i, screenWidth-80-10, 20)];
////                youhuiText.text=MoneytextArray[i];
//                youhuiText.tag=1000+i;
//                youhuiText.font=[UIFont systemFontOfSize:12];
//                youhuiText.textAlignment=NSTextAlignmentRight;
//                youhuiText.textColor=[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0  alpha:1];
//                [fatherView addSubview:youhuiText];
//                
//                
//            }
//            
//            //实付款
//            shifuText=[[UILabel alloc]initWithFrame:CGRectMake(80, 10+140, screenWidth-80-10, 20)];
//            //        shifuText.text=@"实付款：￥150150";
//            shifuText.font=[UIFont systemFontOfSize:12];
//            shifuText.textAlignment=NSTextAlignmentRight;
//            shifuText.textColor=[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0  alpha:1];
//            [fatherView addSubview:shifuText];
//            
//        }
//
//        
//        
//        
//        
//    }
//    
//    if (indexPath.row==order3.pro_data.count+2) {
//        
//        //指定位置变色
//        NSString *ss=[NSString stringWithFormat:@"实付款:￥%.2f",shifuMoney];
//        NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:ss];
//        NSRange redRange = NSMakeRange([[noteStr string] rangeOfString:@":"].location+1,noteStr.length-4 );
//        [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange];
//        [shifuText setAttributedText:noteStr] ;
//        
//        
//        for (int i=0; i<3; i++) {
//            
//            UILabel *find_label = (UILabel *)[self.view viewWithTag:i+1000];
//            
//            find_label.text=MoneytextArray[i];
//        }
//        
//        
//        
//    }
//
//    
//    
//     return cell2;
//    
    
    
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

//拨打电话
- (void)iphoneBUtAction {
    //进入打电话页面
    UIWebView *webview = [[UIWebView alloc] init];
    [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"tel:4008850054"]]];
    [self.view addSubview:webview];
}



- (void)backLogin {
    [self.navigationController popViewControllerAnimated:YES];
}

@end
